package com.qidianit.springboot.controller;

import com.qidianit.springboot.entity.StuDetail;
import com.qidianit.springboot.entity.Student;
import com.qidianit.springboot.mapper.StuDetailMapper;
import com.qidianit.springboot.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2025/4/30 上午 10:41
 * @description
 **/

@RestController
@CrossOrigin
public class StudentController {
    @Autowired
    StudentMapper studentMapper;

    @Autowired
    StuDetailMapper stuDetailMapper;

    @RequestMapping("/selectDetail")
    public Student selectDetail(Integer id) {
        return studentMapper.selectDetail(id);
    }

    @RequestMapping("/selectByNameAndAge")
    public Student selectByNameAndAge(String name,String  email) {
        return studentMapper.selectByNameAndEmail(name,email);
    }


    @RequestMapping("/selectDetailById")
    public Student selectDetailById(Integer id) {
        return studentMapper.selectDetailById(id);
    }


    @RequestMapping("/insertDetail")
    public int insertDetail(Student student, StuDetail stuDetail) {
        if(studentMapper.insert(student)>0){
            stuDetail.setStu_id(student.getId());
            if(stuDetailMapper.insert(stuDetail)>0){
                return 1;
            }
        }
        return 0;
    }


}
